package com.ruoyi.web.controller.young;


import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.young.YContactus;
import com.ruoyi.system.service.young.IYContactusService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 联系我们Controller
 *
 * @author ruoyi
 * @date 2025-01-10
 */
@RestController
@RequestMapping("/young/contactus")
public class YContactusController extends BaseController
{
    @Autowired
    private IYContactusService yContactusService;

    /**
     * 查询联系我们列表
     */
    @PreAuthorize("@ss.hasPermi('system:contactus:list')")
    @GetMapping("/list")
    public TableDataInfo list(YContactus yContactus)
    {
        startPage();
        List<YContactus> list = yContactusService.selectYContactusList(yContactus);
        return getDataTable(list);
    }

    /**
     * 导出联系我们列表
     */
    @PreAuthorize("@ss.hasPermi('system:contactus:export')")
    @Log(title = "联系我们", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YContactus yContactus)
    {
        List<YContactus> list = yContactusService.selectYContactusList(yContactus);
        ExcelUtil<YContactus> util = new ExcelUtil<YContactus>(YContactus.class);
        util.exportExcel(response, list, "联系我们数据");
    }

    /**
     * 获取联系我们详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:contactus:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yContactusService.selectYContactusById(id));
    }

    /**
     * 新增联系我们
     */
    @PreAuthorize("@ss.hasPermi('system:contactus:add')")
    @Log(title = "联系我们", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YContactus yContactus)
    {
        return toAjax(yContactusService.insertYContactus(yContactus));
    }
    /**
     * h5新增联系我们
     */
    @Log(title = "联系我们", businessType = BusinessType.INSERT)
    @PostMapping("/h5/add")
    public AjaxResult addh5(@RequestBody YContactus yContactus)
    {
        return toAjax(yContactusService.insertYContactus(yContactus));
    }

    /**
     * 修改联系我们
     */
    @PreAuthorize("@ss.hasPermi('system:contactus:edit')")
    @Log(title = "联系我们", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YContactus yContactus)
    {
        return toAjax(yContactusService.updateYContactus(yContactus));
    }

    /**
     * 删除联系我们
     */
    @PreAuthorize("@ss.hasPermi('system:contactus:remove')")
    @Log(title = "联系我们", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yContactusService.deleteYContactusByIds(ids));
    }
}
